package com.example.mvpdemo.mvp5.base;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;


public abstract class BaseMvpActivity<V extends BaseView5,P extends BasePresenter5<V>> extends AppCompatActivity {

    private P presenter;
    private V view;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (this.presenter==null){
            this.presenter=createPresenter();
        }
        if (this.view==null){
            this.view=createView();
        }

        if (this.view!=null&&this.presenter!=null){
            this.presenter.attachView(this.view);
        }

    }

    public abstract V createView();

    public abstract P createPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (this.view!=null&&this.presenter!=null){
            this.presenter.detachView(this.view);
        }
    }

    public P getPresenter() {
        return presenter;
    }

}
